<?php

namespace App\Http\Controllers\lxSystem;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Models\Express;

class ExpressController extends Controller
{
    public function index()
    {
        $expresses = Express::orderBy('sort_order')->paginate(5);
        return view('lxSystem.express.index')->with('expresses',$expresses);
    }
    public function create()
    {
        return view('lxSystem.express.create');
    }
    public function store(Request $request)
    {
        Express::create($request->all());
        return redirect(route('express.index'))->with('info', '新增物流成功~');
    }
    public function edit($id)
    {
        $express = Express::find($id);
        return view('lxSystem.express.edit')->with('express' , $express);
    }
    public function update(Request $request, $id)
    {
        $express = Express::find($id);
        $express->update($request->all());
        return redirect(route('express.index'))->with('info', '修改物流信息成功');
    }
    public function destroy($id)
    {
        Express::destroy($id);
        return redirect(route('express.index'))->with('info', '删除物流成功');
    }
    function sort_order(Request $request)
    {
        $express = Express::find($request->id);
        $express->sort_order = $request->sort_order;
        $express->save();
    }

    function is_something(Request $request)
    {
        $attr = $request->attr;
        $express = Express::find($request->id);
        $value = $express->$attr ? false : true;
        $express->$attr = $value;
        $express->save();
    }
}
